package com.lz.zk.regex;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Stack;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lz.zk.model.MethodModel;
import com.lz.zk.model.ClassModel;
import com.lz.zk.model.ParamModel;

import freemarker.template.utility.StringUtil;

public class CodeUtil {
	
	public static Map<String,String> filesMap = new HashMap<String, String>();

	public static ClassModel commit(String str) {
		str = str.replaceAll("\n\t", " ");
		str = str.replaceAll("\n", " ");
		str = str.replaceAll("\r", " ");
		// 将每个class解析出来
		return getClassInfo(str);
	}

	public static List<ClassModel> commitByUrl(String str) {
		List<ClassModel> list = new ArrayList<ClassModel>();
		List<String> clazz = new ArrayList<String>();
		try {
			getFilesByDir(new File(str), clazz);
			for (int i = 0; i < clazz.size(); i++) {
				System.out.println("解析进度：" + (i + 1) + "/" + clazz.size());
				list.add(setReturnEntiy(commit(clazz.get(i))));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public static ClassModel setReturnEntiy(ClassModel model){
		for(MethodModel m : model.getMethod()) {
			String json = JSONObject.toJSONString(m);
			for(Map.Entry<String, String> entry : (CodeUtil.filesMap).entrySet()) {
				
				if(json.indexOf(entry.getKey())!=-1) {
					//m.setMethodRunresult(m.getMethodRunresult()+entry.getValue());
				}
			}
		}
		return model;
	}

//	private static void setEntityInfo(Model model, List<String> classes) {
//		List<EntityModel> entityModel = new ArrayList<EntityModel>();
//		for(int i=1;i<classes.size();i++) {
//			EntityModel entity = new EntityModel();
//			String str=classes.get(i);
//			Pattern pt1 = Pattern.compile("class(.*?)\\{");
//			Matcher match1 = pt1.matcher(str);
//			if (match1.find()) {
//				entity.setName(match1.group(1).replaceAll(" ", ""));
//			}
//			String[] paramArr = (str.substring(str.indexOf("{"),str.lastIndexOf("}"))).split(";");
//			List<Param> params =new ArrayList<Param>();
//			for(String param:paramArr) {
//				if(param.indexOf("**")!=-1) {
//					Param par= new Param();
//					Pattern pt2 = Pattern.compile("/(.*?)/");
//					Matcher match2 = pt2.matcher(param.replace("\n", ""));
//					if (match2.find()) {
//						par.setParamRemark(match2.group(1).replaceAll("\\*", "").replaceAll(" ", ""));
//					}
//					//TODO解析参数的类型，名称
//					par.setParamName(param.substring(param.lastIndexOf(" ")).replaceAll(" ", ""));
//					String type=param.substring(0,param.lastIndexOf(" "));
//					par.setParamType(type.substring(type.lastIndexOf(" ")).replaceAll(" ", ""));
//					params.add(par);
//				}
//			}
//			entity.setParams(params);
//			entityModel.add(entity);
//		}
//		model.setEntity(entityModel);
//	}

	private static String getRootUrl(String head) {
		String rootUrl = "";
		Pattern pt1 = Pattern.compile(".*?Mapping.*?\\(.*?[value]*.*?\"(.*?)\".*?\\)");
		Matcher match1 = pt1.matcher(head);
		if (match1.find()) {
			rootUrl = match1.group(1);
		}
		if (!rootUrl.endsWith("/")) {
			rootUrl = rootUrl + "/";
		}
		return rootUrl;
	}

	private static void setMethodInfo(ClassModel model, String controller, String rootUrl) {
		List<MethodModel> method = new ArrayList<MethodModel>();
		List<String> methods = new ArrayList<String>();
		int i = 0, j = 0;
		;
		while (i++ < controller.length() - 1) {
			if ("{".charAt(0) == controller.charAt(i) && "}".charAt(0) == controller.charAt(i + 1)
					&& "/".charAt(0) != controller.charAt(i - 1)) {
				methods.add(controller.substring(j, i + 2));
				j = i + 2;
				i++;
			}
		}

		if (methods != null) {
			for (String oneMethod : methods) {
				if (oneMethod.indexOf("Mapping") != -1) {
					MethodModel methodModel = new MethodModel();
					List<ParamModel> params = new ArrayList<ParamModel>();

					Pattern pt1 = Pattern.compile(".*?Mapping.*?\\(.*?[value]*.*?\"(.*?)\".*?\\)");
					Matcher match1 = pt1.matcher(oneMethod);
					if (match1.find()) {
						String url = (rootUrl + match1.group(1)).replace("//", "/");
						methodModel.setMethodUrl(url);
						methodModel.setMethodRealUrl(url);
					}
					List<String> requestType = Arrays.asList("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS",
							"TRACE", "Get", "Head", "Post", "Put", "Patch", "Delete", "Options", "Trace");
					Pattern pType1 = Pattern.compile(".*?@(.*?)Mapping.*?");
					Pattern pType2 = Pattern.compile(".*?RequestMethod.(.*?)[\\),]");
					Matcher mType1 = pType1.matcher(oneMethod);
					Matcher mType2 = pType2.matcher(oneMethod);
					if (mType2.find() && requestType.contains(mType2.group(1))) {
						methodModel.setMethodType(mType2.group(1).toUpperCase());
					} else if (mType1.find()) {
						requestType.forEach(e -> {
							if (mType1.group(1).contains(e)) {
								methodModel.setMethodType(e.toUpperCase());
							}
						});
					}
					String paramM = getParamStr(oneMethod);
					if (!paramM.equals("")) {
						List<String> tArr = getRealArr(Arrays.asList(paramM.split(",")),
								m->{return countCharAppear(m,Arrays.asList('(',')'))%2!=0 || countCharAppear(m,Arrays.asList('('))!=countCharAppear(m,Arrays.asList(')')) || countCharAppear(m,Arrays.asList('<','>'))%2!=0 || countCharAppear(m,Arrays.asList('<'))!=countCharAppear(m,Arrays.asList('>'));},
								n->{return countCharAppear(n,Arrays.asList('(',')'))%2==0 && countCharAppear(n,Arrays.asList('('))==countCharAppear(n,Arrays.asList(')')) && countCharAppear(n,Arrays.asList('<','>'))%2==0 && countCharAppear(n,Arrays.asList('<'))==countCharAppear(n,Arrays.asList('>'));});
						for (int t = tArr.size() - 1; t >= 0; t--) {
							String paramStr = tArr.get(t);
							ParamModel param = getParamByParamStr(paramStr);
							Pattern pattern = Pattern.compile("[a-zA-Z_$][a-zA-Z_0-9$]*");
							Matcher matcher = pattern.matcher(param.getParamName());
							if (matcher.find()) {
								// System.out.println(oneMethod);
								Pattern pt3 = null;
								if(param.getParamName()!=null&&param.getParamName().indexOf("[")!=-1) {
									pt3 = Pattern.compile(".*?@param.*?"+(param.getParamName().replaceAll("\\[", "\\\\\\\\[").replaceAll("\\]", "\\\\\\\\]"))+"(.*?)@");
								}else {
									pt3 = Pattern.compile(".*?@param.*?" + param.getParamName() + "(.*?)@");
								}
								Matcher match3 = pt3.matcher(oneMethod.replaceAll("\r\n", ""));
								if (match3.find()) {
									if (isContainChinese(match3.group(1)))
										param.setParamRemark(
												match3.group(1).replaceAll(" ", "").replaceAll("\\*", ""));
								}
								params.add(param);
							}
						}
					}
					String mparam = "("+paramM+")";
					String mn = oneMethod.substring(0,oneMethod.indexOf(mparam));
					//String abc [] = mn.split(" ");
					List<String> abc = getRealArr(Arrays.asList(mn.split("[,| ]")),m->{return (countCharAppear(m,Arrays.asList('<','>'))%2!=0 || countCharAppear(m,Arrays.asList('<'))!=countCharAppear(m,Arrays.asList('>')));},
							n->{return countCharAppear(n,Arrays.asList('<','>'))%2==0 && countCharAppear(n,Arrays.asList('<'))==countCharAppear(n,Arrays.asList('>'));});
					methodModel.setMethodName(abc.get(0));
					methodModel.setMethodReturn(abc.get(1));
					System.out.println(abc.get(1));
					Pattern pt3 = Pattern.compile(".*?@return(.*?)@");
					Matcher match3 = pt3.matcher(oneMethod);
					if (match3.find()) {
						methodModel.setMethodReturnRemark(match3.group(1).replaceAll(" ", ""));
					}
//					Pattern pt4 = Pattern.compile("\\*.*?<(.*?)>.*?");
//					Matcher match4 = pt4.matcher(oneMethod);
//					if (match4.find() && isContainChinese(match4.group(1))) {
//						methodModel.setMethodRemark(match4.group(1));
//					}
					//Pattern pt4 = Pattern.compile(".*?<(.*?)>.*?");
					Pattern pt4 = Pattern.compile("\\*.*?<(.*?)>.*?");
					Matcher match4 = pt4.matcher(oneMethod.substring(0, oneMethod.indexOf("@")));
					if (match4.find()) {
						methodModel.setMethodRemark(match4.group(1));
					}else {
						Pattern ppt4 = Pattern.compile(".*?//(.*?)@.*?");
						Matcher pmatch4 = ppt4.matcher(oneMethod);
						if (pmatch4.find()) {
							methodModel.setMethodRemark(pmatch4.group(1));
						}else {
							Pattern pppt4 = Pattern.compile(".*?\\/\\*(.*?)@.*?");
							Matcher ppmatch4 = pppt4.matcher(oneMethod);
							if (ppmatch4.find()) {
								methodModel.setMethodRemark(ppmatch4.group(1));
							}
						}
					}
					methodModel.setMethodRemark(methodModel.getMethodRemark()==null?null:methodModel.getMethodRemark().replaceAll("\\*", "").replaceAll(" ", ""));
					
					methodModel.setMethodParam(params);
					methodModel.setMethodRunstatus("未执行");
					methodModel.setMethodRunresult(getReturnModelArr(methodModel.getMethodReturn()));
					method.add(methodModel);
				}
			}
		}
		model.setMethod(method);
	}
	

	public static List<String> getRealArr(List<String> tempP,Function<String,Boolean> f1,Function<String,Boolean> f2) {
		List<String> arr = new ArrayList<String>();
		for (int t = tempP.size() - 1; t >= 0; t--) {
			if (tempP.get(t) != null && !StringUtils.isEmpty(tempP.get(t)) && f1.apply(tempP.get(t))) {
				int m = t;
				while (m-- > 0) {
					if(tempP.get(m)==null||StringUtils.isEmpty(tempP.get(m))) {
						continue;
					}
					tempP.set(t, tempP.get(m) + "," + tempP.get(t));
					if (f2.apply(tempP.get(t))) {
						t = m;
						tempP.set(m, null);
						break;
					}
					tempP.set(m, null);
				}
			}
		}
		for (int t = tempP.size() - 1; t >= 0; t--) {
			if(!StringUtils.isEmpty(tempP.get(t))) {
				arr.add(tempP.get(t));
			}
		}
		return arr;
	}

	/**
	 * <截取参数string>
	 * 
	 * @param str
	 * @return
	 */
	private static String getParamStr(String str) {
		List<Integer> indexs = new ArrayList<Integer>();
		for (int i = 0; i < str.length(); i++) {
			if ("(".equals(str.charAt(i) + "") || ")".equals(str.charAt(i) + "")) {
				indexs.add(i);
			}
		}
		if (indexs.size() <= 2) {
			return "";
		}
		for (int j = indexs.size() - 2; j > 0; j--) {
			if (")".equals("" + str.charAt(indexs.get(j)))) {
				j--;
			} else {
				return str.substring(indexs.get(j) + 1, indexs.get(indexs.size() - 1));
			}
		}
		return str;
	}
	
	/**
	 * <截取单个参数string>
	 * 
	 * @param str
	 * @return
	 */
	private static String getSingleParamStr(String str) {
		List<Integer> indexs = new ArrayList<Integer>();
		for (int i = 0; i < str.length(); i++) {
			if ("(".equals(str.charAt(i) + "") || ")".equals(str.charAt(i) + "")) {
				indexs.add(i);
			}
		}
		if (indexs.size() <= 2) {
			return "";
		}
		for (int j = indexs.size() - 2; j > 0; j--) {
			if (")".equals("" + str.charAt(indexs.get(j)))) {
				j--;
			} else {
				return str.substring(indexs.get(j) + 1, indexs.get(indexs.size() - 1));
			}
		}
		return str;
	}

	/**
	 * 方法体去掉
	 * 
	 * @param controller
	 * @return
	 */
	private static String convertToDeal(String controller) {
		// System.out.println(controller);
		List<Integer> a = new ArrayList<Integer>();
		List<Integer> b = new ArrayList<Integer>();
		List<Integer> c = new ArrayList<Integer>();
		List<Integer> d = new ArrayList<Integer>();
		for (int i = 0; i < controller.length(); i++) {
			if ("{".charAt(0) == (controller.charAt(i))) {
				a.add(i);
			}
			if ("}".charAt(0) == (controller.charAt(i))) {
				b.add(i);
			}
			if (i > 0 && "{".charAt(0) == (controller.charAt(i)) && "/".charAt(0) == (controller.charAt(i - 1))) {
				d.add(i);
			}
			int t = i;
			while (t-- > 0) {
				if ("(".charAt(0) == (controller.charAt(t))) {
					d.add(i);
				}
				if (")".charAt(0) == (controller.charAt(t))) {
					break;
				}
			}
		}
		for (int j = 0; j < b.size(); j++) {
			for (int k = a.size() - 1; k > -1; k--) {
				if (!c.contains(a.get(k)) && b.get(j) > a.get(k)) {
					c.add(a.get(k));
					c.add(b.get(j));
					break;
				}
			}
		}
		for (int l = c.size() - 1; l > 0; l = l - 2) {
			int flag = 0;
			for (int m = 0; m < c.size(); m = m + 2) {
				if ((c.get(m + 1) > c.get(l) && c.get(m) < c.get(l - 1))) {
					flag = 1;
				}
			}
			if (flag == 0 && !d.contains(c.get(l - 1))) {
				String x = controller.substring(0, c.get(l - 1) + 1);
				String y = controller.substring(c.get(l));
				controller = x + y;
			}
		}
		return controller;
	}

	/**
	 * 判断字符串中是否包含中文
	 * 
	 * @param str 待校验字符串
	 * @return 是否为中文
	 * @warn 不能校验是否为中文标点符号
	 */
	public static boolean isContainChinese(String str) {
		Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
		Matcher m = p.matcher(str);
		if (m.find()) {
			return true;
		}
		return false;
	}

	/**
	 * 解析class信息
	 * 
	 * @param str
	 * @return
	 */
	public static ClassModel getClassInfo(String str) {
		String head = str.substring(str.lastIndexOf("import "), str.indexOf("class"));
		ClassModel mod = new ClassModel();
		//Pattern pt1 = Pattern.compile(".*?<(.*?)>.*?");
		Pattern pt1 = Pattern.compile(".*?<(.*?)>.*?");
		Matcher match1 = pt1.matcher(head.substring(0, head.indexOf("@")));
		if (match1.find()) {
			mod.setRemark(match1.group(1));
		}else {
			Pattern ppt1 = Pattern.compile(".*?//(.*?)@.*?");
			Matcher pmatch1 = ppt1.matcher(head);
			if (pmatch1.find()) {
				mod.setRemark(pmatch1.group(1));
			}else {
				Pattern pppt1 = Pattern.compile(".*?\\/\\*(.*?)@.*?");
				Matcher ppmatch1 = pppt1.matcher(head);
				if (ppmatch1.find()) {
					mod.setRemark(ppmatch1.group(1));
				}
			}
		}
		mod.setRemark(mod.getRemark()==null?null:mod.getRemark().replaceAll("\\*", "").replaceAll(" ", ""));
		Pattern pt2 = Pattern.compile(".*?@author(.*?)[@|\\*/].*?");
		Matcher match2 = pt2.matcher(head);
		if (match2.find()) {
			mod.setAuthor(match2.group(1));
		}
		Pattern pt3 = Pattern.compile(".*?@version(.*?)[@|\\*/].*?");
		Matcher match3 = pt3.matcher(head);
		if (match3.find()) {
			mod.setVersion(match3.group(1));
		}
		Pattern p1 = Pattern.compile("package(.*?);");
		Matcher m1 = p1.matcher(str);
		if (m1.find()) {
			mod.setPackageName(m1.group(1).replaceAll(" ", ""));
		}
		str = str.substring(str.indexOf("class") + 5);
		Pattern p2 = Pattern.compile("(.*?)(implements|extends|\\{).*?");
		Matcher m2 = p2.matcher(str);
		if (m2.find()) {
			mod.setName(m2.group(1).replaceAll(" ", ""));
		}
		str = convertToDeal(str.substring(str.indexOf("{") + 1, str.lastIndexOf("}")));
		setMethodInfo(mod, str, getRootUrl(head));
		return mod;
	}

	static void getFilesByDir(File f, List<String> fileStrs) throws IOException {
		System.out.println("扫描文件：" + f.getAbsolutePath());
		if (f.exists()) {
			if (f.isFile() && f.getAbsolutePath().endsWith(".java")) {
				StringBuffer buffer = new StringBuffer();
				BufferedReader bf = new BufferedReader(new FileReader(f));
				String s = null;
				while ((s = bf.readLine()) != null) {// 使用readLine方法，一次读一行
					buffer.append(s.trim()).append(" ");
				}
				if ((buffer.toString().indexOf("@RestController") != -1
						|| buffer.toString().indexOf("@Controller") != -1)
						&& buffer.toString().indexOf("Mapping") != -1)
					fileStrs.add(buffer.toString());
				CodeUtil.filesMap.put(f.getName().substring(0,f.getName().lastIndexOf(".java")), buffer.toString());
			} else if (f.isDirectory()) {
				for (File file : f.listFiles()) {
					getFilesByDir(file, fileStrs);
				}
			}
		}
	}
	
	static int countCharAppear(String str,List<Character> chars) {
		int sum=0;
		for(int i=0;i<str.length();i++) {
			if(chars.contains(str.charAt(i))) {
				sum++;
			}
		}
		return sum;
	}
	
	static List<String> paramType1 = Arrays.asList("byte", "short", "int", "long", "float", "double", "boolean","char");
	static List<String> paramType2 = Arrays.asList("Byte", "Short", "Integer", "Long", "Float", "Double", "Boolean","Character","Object");
	static List<String> paramType3 = Arrays.asList("List","ArrayList","Set","HashSet");
	static List<String> paramType4 = Arrays.asList("Map","HashMap");
	static List<String> paramType5 = Arrays.asList("Object");
	
	static String getReturnModelArr(String str){
		String[] models = str.split("[<|>|,| ]");
		return getText(models,0);
	}
	
	
	static String getText(String[] list, int index) {
		if(list[index].equals("PageInfo")) {
			return "{\"pageNum\":1,\"pageSize\":10,\"size\":10,\"orderBy\":null,\"startRow\":1,\"endRow\":10,\"total\":12,\"pages\":2,\"list\":["+getText(list,index+1)+"],\"prePage\":0,\"nextPage\":2,\"isFirstPage\":true,\"isLastPage\":false,\"hasPreviousPage\":false,\"hasNextPage\":true,\"navigatePages\":8,\"navigatepageNums\":[1,2],\"navigateFirstPage\":1,\"navigateLastPage\":2,\"firstPage\":1,\"lastPage\":2}";
		}
		if(list[index].equals("List")||list[index].equals("ArrayList")||list[index].equals("Set")||list[index].equals("HashSet")) {
			return "[" +getText(list,index+1)+ "]";
		}if(list[index].equals("Map")||list[index].equals("HashMap")) {
			return "{" +getText(list,index+1)+","+getText(list,index+2)+ "}";
		}
		String type = list[index];
		for(String x:paramType1) {
			if(x.equals(type)) {
				return null;
			}
		}
		for(String x:paramType2) {
			if(x.equals(type)) {
				return null;
			}
		}
		for(String x:paramType5) {
			if(x.equals(type)) {
				return null;
			}
		}
		for(Entry<String, String> entry:CodeUtil.filesMap.entrySet()) {
			if(entry.getKey().equals(list[index])) {
				List<ParamModel> params = getClassFileds(entry.getValue());
				String s = "";
				for(ParamModel p : params) {
					s=s+"\""+p.getParamName()+"\":"+p.getParamRemark()+",";
				}
				return "{"+s.substring(0,s.lastIndexOf(","))+"}";
			}
		}
		return list[index];
	}
	
	
	public static void main(String[] args) {
		ArrayList<String> list = new ArrayList<String>();
		System.out.println(getReturnModelArr("Map<String,Map<String,Integer>>"));
	}

	/**
	 * 获取类里的参数
	 * @param clazz
	 * @return
	 */
	public static List<ParamModel> getClassFileds(String clazz) {
		List<ParamModel> params = new ArrayList<ParamModel>();
		clazz = clazz.replaceAll("\n\t", " ");
		clazz = clazz.replaceAll("\n", " ");
		clazz = clazz.replaceAll("\r", " ");
		clazz = convertToDeal(clazz.substring(clazz.indexOf("{"),clazz.lastIndexOf("}")));
		String[] arr = clazz.split(";");
		List<String> finalArr = new ArrayList<String>();
		for(String s:arr) {
			if((!s.contains("(")&&!s.contains("{"))||s.contains("=")) {
				finalArr.add(s);
			}
		}
		for(String p:finalArr) {
			String fliedText=p.contains("=")?p.substring(0, p.indexOf("=")):p;
			ParamModel param = getParamByParamStr(fliedText);
			params.add(param);
		}
		return params;
	}
	
	/**
	 * 提取参数
	 * @param paramStr
	 * @return
	 */
	public static ParamModel getParamByParamStr(String paramStr) {
		ParamModel param = new ParamModel();
		param.setParamNeed("false");
		//提取参数名和参数类型
		String[] tempP = new String[] {};
		tempP = paramStr.split("[...|)|,|(| ]");
		for (int t = tempP.length - 1; t > 0; t--) {
			if (tempP[t] != null && (countCharAppear(tempP[t],Arrays.asList('<','>'))%2!=0 || countCharAppear(tempP[t],Arrays.asList('<'))!=countCharAppear(tempP[t],Arrays.asList('>')))) {
				int m = t;
				while (m-- > 0) {
					tempP[t] = tempP[m] + "," + tempP[t];
					if (countCharAppear(tempP[t],Arrays.asList('<','>'))%2==0 && countCharAppear(tempP[t],Arrays.asList('<'))==countCharAppear(tempP[t],Arrays.asList('>'))) {
						t = m;
						tempP[m] = null;
						break;
					}
					tempP[m] = null;
				}
			}
		}
		int x = tempP.length;
		while(--x>=0) {
			if(!StringUtils.isEmpty(tempP[x])) {
				param.setParamName(tempP[x]);
				break;
			}
		}
		while(--x>=0) {
			if(!StringUtils.isEmpty(tempP[x])) {
				param.setParamType(tempP[x]);	
				break;
			}
		}
		//提取注释
		Pattern paramP1 = Pattern.compile(".*?/\\*(.*?)\\*/");
		Matcher paramM1 = paramP1.matcher(paramStr);
		if (paramM1.find()) {
			param.setParamRemark(paramM1.group(1).replaceAll("\\*", "").replaceAll(" *", ""));
		}else {
			if(param.getParamType()!=null&&param.getParamType().indexOf("[")!=-1) {
				paramP1 = Pattern.compile(".*?//(.*?)"+(param.getParamType().replaceAll("\\[", "\\\\\\\\[").replaceAll("\\]", "\\\\\\\\]"))+".*?");
			}else {
				paramP1 = Pattern.compile(".*?//(.*?)"+param.getParamType()+".*?");
			}
			paramM1 = paramP1.matcher(paramStr);
			if (paramM1.find()) {
				param.setParamRemark(paramM1.group(1).replaceAll("\\*", "").replaceAll(" *", ""));
			}
		}
		//提取是否必须
		Pattern paramP2 = Pattern.compile(".*?@.*?required.*?=(.*?)[\\)|,]");
		Matcher paramM2 = paramP2.matcher(paramStr);
		if ((paramM2.find() && (paramM2.group(1).indexOf("false") != -1))
				|| (paramStr.indexOf("defaultValue") != -1)
				|| (paramStr.indexOf("@") == -1)) {
			param.setParamNeed("false");
		} else {
			param.setParamNeed("true");
		}
		//提取默认值
		Pattern paramP3 = Pattern.compile(".*?@.*?defaultValue.*?=(.*?)[\\)|,]");
		Matcher paramM3 = paramP3.matcher(paramStr);
		if (paramM3.find()) {
			param.setParamValue(
					paramM3.group(1).replaceAll(" ", "").replaceAll("\"", ""));
		}
		return param;
	}

}
